package com.ihisun.tmhcms.controller.mechanismcontroller;

import com.ihisun.tmhcms.core.dto.mechanismdto.EditMechanismDto;
import com.ihisun.tmhcms.core.dto.mechanismdto.EditMechanismTypeDto;
import com.ihisun.tmhcms.core.dto.mechanismdto.SearchMechanismDto;
import com.ihisun.tmhcms.core.service.machanismservice.MachanismService;
import com.ihisun.tmhcms.core.vo.MechanismTypeVo;
import com.ihisun.tmhcms.utils.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Slf4j
@Api(tags = "机构相关Api")
@RestController
@RequestMapping("/mechanism")
public class MechanismController {

    @Resource
    MachanismService machanismService;

    @PostMapping("/addMechanismType")
    @ApiOperation(value = "编辑机构分类", response = EditMechanismTypeDto.class)
    public ResponseVo addMechanismType(@RequestBody EditMechanismTypeDto mechanismTypeDto) {
        return machanismService.addMachanismType(mechanismTypeDto);
    }



    @GetMapping("/deleteMechanismTypy")
    @ApiOperation(value = "修改机构分类状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "typeId", value = "分类id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "valueState", value = "状态 1正常  2冻结  3删除", dataType = "String", paramType = "query")
    })
    public ResponseVo deleteMechanismTypy(String typeId, String valueState) {
        ResponseVo responseVo = machanismService.deleteMchanismType(typeId, Integer.valueOf(valueState));

        return responseVo;
    }

    @GetMapping("/searchMechanismClass")
    @ApiOperation(value = "搜机构分类",response = MechanismTypeVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mechanismTypeName",value = "机构分类名",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "条数",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageNum",value = "页码",dataType = "String",paramType = "query")
    })

    public ResponseVo searchMechanismType(String mechanismTypeName,String pageNum,String pageSize){
        return machanismService.searchMechanismType(mechanismTypeName,Integer.parseInt(pageNum),Integer.parseInt(pageSize));
    }


    @PostMapping("editMechanism")
    @ApiOperation(value = "编辑机构", response = EditMechanismDto.class)
    public ResponseVo editMechanism(@RequestBody EditMechanismDto editMechanismDto) {

        return machanismService.editMechanism(editMechanismDto);
    }


    @PostMapping("/searchMechanism")
    @ApiOperation(value = "收索机构", response = SearchMechanismDto.class)
    public ResponseVo searchMechanism(@RequestBody SearchMechanismDto searchMechanismDto) {
            log.info("searchMechanismDto:"+searchMechanismDto);
        ResponseVo responseVo = machanismService.searchMechanism(searchMechanismDto);
        return responseVo;
    }


}
